<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        select {
            width: 500px;
            height: 500px;
        }
    </style>
</head>
<body>
    <select name="" id="sel1" multiple>
        <option value="" >苹果</option>
        <option value="">梨子</option>
        <option value="">西瓜</option>
        <option value="">菠萝</option>
    </select>
    <button id="btn1">&gt;</button>
    <button id="btn2">&lt;</button>
    <button id="btn3">&gt;&gt;</button>
    <button id="btn4">&lt;&lt;</button>
    <select name="" id="sel2" multiple></select>
    <script>
        //获取元素
        var sel1 = document.getElementById('sel1');
        var sel2 = document.getElementById('sel2');
        var btn1 = document.getElementById('btn1');
        var btn2 = document.getElementById('btn2');
        var btn3 = document.getElementById('btn3');
        var btn4 = document.getElementById('btn4');

        //注册事件
        //选中的从左边到右边
        btn1.onclick = function() {
            for(var i = 0; i < sel1.children.length; i++) {
                if(sel1.children[i].selected) {
                    sel2.appendChild(sel1.children[i])
                    i--;
                }
            }
        }
        //选中的从右边到左边
        btn2.onclick = function() {
            for(var i = 0; i < sel2.children.length; i++) {
                if(sel2.children[i].selected) {
                    sel1.appendChild(sel2.children[i])
                    i--;
                }
            }
        }
        //全部从左边到右边
        btn3.onclick = function() {
            for(var i = 0; i < sel1.children.length; i++) {
                sel2.appendChild(sel1.children[i]);
                i--;
            }
        }
        //全部右边到左边
        btn4.onclick = function() {
            for(var i = 0; i < sel2.children.length; i++) {
                sel1.appendChild(sel2.children[i]);
                i--;
            }
        }
    </script>
</body>
</html>